package chapter03;

public class Account {
    public static void main(String[] args) {
        Account a = new Account("张三",10000);
        a.checkedAccount();
        a.deposit(10000);
        a.checkedAccount();
        System.out.println("第一次取款");
        a.withdraw(10000);
        a.checkedAccount();
        System.out.println("第二次取款");
        a.withdraw(20000);
        a.checkedAccount();
    }
    private String accountName;
    private double balance;
    public Account(String accountName, double balance) {
        this.accountName = accountName;
        this.balance = balance;
    }
    //存款
    public void deposit(double money){
        this.balance = this.balance+money;
    }
    public void withdraw(double money){
        if(this.balance<money){
            System.out.println("余额不足,取款失败");
        }else{
            this.balance = this.balance-money;
        }
    }
    public void checkedAccount(){
        System.out.println("账户名："+accountName);
        System.out.println("账户余额："+balance);
    }
}
